package com.bit.aop.proxy;

//import net.sf.cglib.proxy.Enhancer;

import org.springframework.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

public class Main {
    public static void main(String[] args) {
        //静态代理
//        HouseProxy houseProxy = new HouseProxy(new RealHouseSubject());
//        houseProxy.saleHouse();
//        houseProxy.rentHouse();

        //动态代理
        HouseSubject target = new RealHouseSubject(); //目标对象
        //生成代理类
        HouseSubject proxy1 = (HouseSubject) Proxy.newProxyInstance(target.getClass().getClassLoader(),
                new Class[]{HouseSubject.class}, new JDKInvocation(target));
        proxy1.rentHouse();
        proxy1.saleHouse();

        HouseSubject proxy = (HouseSubject) Enhancer.create(HouseSubject.class, new CglibMethodInteceptor(target));
        proxy.saleHouse();

    }
}
